package com.neusoft.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neusoft.domain.Business;
import com.neusoft.domain.PageResult;
import com.neusoft.mapper.BusinessMapper;
import com.neusoft.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    private BusinessMapper businessMapper;
    @Override
    public PageResult<Business> pageSelectBusiness(Integer pageNum, Integer pageSize, String account, String telephone) {
        PageHelper.startPage(pageNum,pageSize);

        List<Business>list=businessMapper.pageSelectBusiness(account,telephone);
        PageInfo<Business>pageInfo=new PageInfo<>(list);
        PageResult<Business>pageResult=new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return pageResult;

    }

    @Override
    public void updateBusiness(Business business) {

        businessMapper.updateBusiness(business);
    }

    @Override
    public void deleteBusiness(Integer id) {
        businessMapper.deleteBusiness(id);
    }

    @Override
    public void addBusiness(Business business) {
        business.setReg_time(LocalDate.now());
        businessMapper.addBusiness(business);
    }
}
